import 'package:flutter/material.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/utils/toast_util.dart';
import 'package:library_base/utils/widget_generate_util.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:module_administrator/page/workbench_controller.dart';
import 'package:library_base/widget/button/ink_bg_well.dart';

class WorkbenchPage extends StatefulWidget {
  const WorkbenchPage({Key? key}) : super(key: key);

  @override
  _WorkbenchPageState createState() => _WorkbenchPageState();
}

class _WorkbenchPageState extends BaseState<WorkbenchPage, WorkbenchController> {
  late List<String> images;

  late List<String> functionStr;

  initTaskItem() {
    images = [
      'order_task9',
      'order_task1',
      'order_task2',
      'order_task3',
      'order_task5',
      'order_task6',
      'order_task7',
      'order_task8'
    ];
    functionStr = [
      MultiLanguage.summaryOfRequirements.tr,
      MultiLanguage.purchasingTasks.tr,
      MultiLanguage.createPurchaseOrder.tr,
      MultiLanguage.purchasePayment.tr,
      MultiLanguage.supplierQuotation.tr,
      MultiLanguage.mobileReimbursement.tr,
      MultiLanguage.inventoryTask.tr,
      MultiLanguage.outboundTask.tr,
      MultiLanguage.weighDelivery.tr
    ];
  }

  @override
  void onCreate() {
    setNavigationBarVisible(false);
    setStatusBarVisible(false);
  }

  @override
  void onResume() {
    super.onResume();
    baseGetxController!.workbench();
  }

  List<Widget> _generateItem() {
    List<Widget> items = [];
    for (int i = 0; i < 4; i++) {
      items.add(
          imageWithTextWorkbench(images[i], functionStr[i], fit: BoxFit.fitWidth, onTap: action));
    }
    return items;
  }

  void action(String action) {
    if (action == MultiLanguage.purchasingTasks.tr) {
      Get.toNamed(Routers.purchaseOrderTask);
    } else if (action == MultiLanguage.createPurchaseOrder.tr) {
      Get.toNamed(Routers.createPurchaseOrderPage);
    } else if (action == MultiLanguage.supplierQuotation.tr) {
      ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
    } else if (action == MultiLanguage.summaryOfRequirements.tr) {
      Get.toNamed(Routers.summaryListPage);
    } else if (action == MultiLanguage.mobileReimbursement.tr) {
      ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
    } else if (action == MultiLanguage.inventoryTask.tr) {
      ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
    } else if (action == MultiLanguage.outboundTask.tr) {
      ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
    } else if (action == MultiLanguage.weighDelivery.tr) {
      ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
    } else if (action == MultiLanguage.purchasePayment.tr) {
      Get.toNamed(Routers.purchasePaymentPage);
    }
  }

  static Widget generateItem(String name, String image, String count, {GestureTapCallback? onTap}) {
    return GestureDetector(
      onTap: onTap,
      child: Stack(
        children: [
          LocalImage(image,
              package: Constant.packAdmin(), width: double.infinity, fit: BoxFit.fitWidth),
          Padding(
              padding: edgeL25T31,
              child: Text(name, style: TextStyles.textWhite28)),
          Padding(
              padding: edgeL25T85,
              child: Text(count, style: TextStyles.textWhite62))
        ],
      ),
    );
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    initTaskItem();
    return SingleChildScrollView(
      child: Stack(
        children: [
          LocalImage('order_manage_bg',
              package: Constant.packAdmin(), width: double.infinity, fit: BoxFit.fitWidth),
          Column(
            children: [
              Gaps.vGap134,
              Container(
                padding: EdgeInsets.symmetric(horizontal: 24.w),
                child: LocalImage('order_manage1',
                    package: Constant.packAdmin(), width: double.infinity, fit: BoxFit.fitWidth),
              ),
              Row(
                children: [
                  gapW24,
                  Expanded(
                    child: GetBuilder<WorkbenchController>(
                      builder: (logic) {
                        return generateItem(MultiLanguage.toBePurchased.tr, 'order_manage_mask1',
                            baseGetxController!.purchaseCount,
                            onTap: () {});
                      },
                    ),
                  ),
                  gapW16,
                  Expanded(
                    child: GetBuilder<WorkbenchController>(
                      builder: (logic) {
                        return generateItem(MultiLanguage.unpaidApplication.tr, 'order_manage_mask4',
                            baseGetxController!.inquiredCount,
                            onTap: () {});
                      },
                    ),
                  ),
                  gapW24,
                ],
              ),
              SizedBox(height: 16.w),
              Visibility(
                visible: false,
                child: Row(
                  children: [
                    gapW24,
                    Expanded(
                      child: GetBuilder<WorkbenchController>(
                        builder: (logic) {
                          return generateItem(MultiLanguage.toBeWarehoused.tr, 'order_manage_mask3',
                              baseGetxController!.warehousedCount,
                              onTap: () {});
                        },
                      ),
                    ),
                    Gaps.hGap16,
                    Expanded(
                      child: GetBuilder<WorkbenchController>(
                        builder: (logic) {
                          return generateItem(MultiLanguage.toBedelivered.tr, 'order_manage_mask4',
                              baseGetxController!.deliveredCount,
                              onTap: () {});
                        },
                      ),
                    ),
                    gapW24,
                  ],
                ),
              ),
              Visibility(visible: false, child: gapH24),
              Container(
                margin: GenerateWidgetUtil.tipGapOnlyLeft(),
                padding: GenerateWidgetUtil.tipVGap(),
                decoration: BoxDecoration(
                    color: ThemeUtil.getTheme().tipBgColor(),
                    borderRadius: const BorderRadius.only(
                        topLeft: Radius.circular(20), bottomLeft: Radius.circular(20))),
                child: Row(children: [
                  gapW24,
                  LocalImage('order_manage2',
                      package: Constant.packAdmin(), width: 40.w, height: 40.w, fit: BoxFit.cover),
                  gapW24,
                  Expanded(
                      child: Text('公告 更新提示：发版内容，点击查阅，更新提示...',
                          overflow: TextOverflow.ellipsis, style: TextStyles.textOrange26)),
                  gapW24,
                  LocalImage('orange_rightward_arrow',
                      package: Constant.packAdmin(),
                      width: 21.w,
                      height: 21.w,
                      fit: BoxFit.fitWidth),
                  gapW24,
                ]),
              ),
              gapH24,
              Container(
                width: double.infinity,
                height: 294.w / 2,
                margin: GenerateWidgetUtil.pageHGap(),
                decoration: BoxDecoration(
                  color: ThemeUtil.getTheme().colorScheme.secondary,
                  borderRadius: const BorderRadius.all(Radius.circular(8)),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black.withOpacity(0.1), // 阴影的颜色
                      offset: const Offset(0, 0), // 阴影与容器的距离
                      blurRadius: 10.0, // 高斯的标准偏差与盒子的形状卷积。
                      spreadRadius: 0.0, // 在应用模糊之前，框应该膨胀的量。
                    ),
                  ],
                ),
                child: GridView(
                  padding: const EdgeInsets.all(0),
                  children: _generateItem(),
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 4,
                    mainAxisSpacing: 0.w,
                    crossAxisSpacing: 0.w,
                    childAspectRatio: 1.19,
                  ),
                ),
              ),
              GestureDetector(
                  onTap: () {
                    Get.back();
                  },
                  child: Container(
                      alignment: Alignment.centerRight,
                      margin: EdgeInsets.only(top: 100.w, right: 24.w),
                      child: LocalImage('order_manage3',
                          package: Constant.packAdmin(),
                          width: 130.w,
                          height: 130.w,
                          fit: BoxFit.cover)))
            ],
          ),
        ],
      ),
    );
  }

  @override
  WorkbenchController registerController() => Get.find<WorkbenchController>();
}
